package org.hgvc.webapp.ets.spring.dao;

import java.util.List;


import org.hgvc.webapp.ets.bo.ActionBulletin;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hibernate.Query;
import org.jocsb.base.AbstractHibernateDao;
import org.jocsb.base.bo.User;


public class SystemHbmDao extends AbstractHibernateDao {

	
	public List<ActionBulletin> getActionBulletinListByUserId(String userId)throws Exception{
		StringBuffer str = new StringBuffer();
		str.append(" select ab from ActionBulletin ab where ab.isDeleted=:value and ab.user.userId=:userId order by ab.createdDate asc");
		
		Query query = getSession().createQuery(str.toString());
		query.setParameter("value", CommonConstant.NOT_DELETED);
		query.setParameter("userId", userId);
		
		return (List<ActionBulletin>)query.list();
	}
	
	public void deleteActionBulletinByActionNo(String actionNo)throws Exception{
		StringBuffer str = new StringBuffer();
		str.append(" delete from ActionBulletin ab where ab.actionNo=:actionNo");
		
		Query query = getSession().createQuery(str.toString());
		query.setParameter("actionNo", actionNo);
		
		query.executeUpdate();
	}
	
	public List<User> getUsersByRole(String roleId)throws Exception{
		
		StringBuffer str = new StringBuffer();
		str.append(" select user from User user,UserRole usr where usr.role.roleId=:roleId and user.userId = usr.user.userId ");
		
		Query query = getSession().createQuery(str.toString());
		query.setParameter("roleId", roleId);
		
		return (List<User>)query.list();
	}
}
